// 导入用户集合
const { News } = require('../../../model/news');
// 引入分页模块
const pagination = require('mongoose-sex-page')
const { newsState } = require('../../../enum/state')
const { decodeToken } = require('../../../middleGuard/jwt')

module.exports = async (req, res) => {
  const { index, size } = req.query
  const query = {
    // state: newsState.pending
  }
  query.user = decodeToken(req.headers.authorization).userId
  console.log(query)
  const list = await pagination(News).find(query).sort({_id: -1}).page(index).size(size).populate('user').exec()
  res.json({
      data: list
  })
}